﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using DTO;
using BUS;
using System.Xml;

namespace WebRaoVat
{
    public partial class DangNhap : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Page_PreInit(object sender, EventArgs e)
        {
            Page.Theme = ((XmlElement)XL_XML.ReadNodeSingle(XL_XML.ReadDocumentFile(Server.MapPath("Gui.xml")),
            "/GIAODIEN/THEME")).GetAttribute("ten");
        }

        protected void btnDanhNhap_Click(object sender, EventArgs e)
        {
            string strUsername = txtUsername.Text.Trim().ToLower();
            string strPassword = txtPassword.Text.Trim();

            NguoiDungDTO nguoiDung = NguoiDungBUS.layNguoiDungTheoTen(strUsername);

            if (nguoiDung != null)
            {
                if (strPassword.CompareTo(nguoiDung.MatKhau) == 0)
                {
                    Session["NguoiDungDangDangNhap"] = nguoiDung.TenNguoiDung;

                    if (Session["TrangHienTai"] != null && Session["TrangHienTai"].ToString().Length > 0)
                    {
                        Response.Redirect(Session["TrangHienTai"].ToString());
                    }
                    else
                    {
                        Response.Redirect("Default.aspx");
                    }

                    return;
                }
            }

            //Không đúng
            lbMessage.Text = "Tên hoặc mật khẩu không đúng !";
        }
    }
}
